package com.arcsoft.arcfacesingle.charge.server;

import com.arcsoft.arcfacesingle.charge.server.model.TestConstants;
import com.arcsoft.arcfacesingle.charge.server.model.request.*;
import com.arcsoft.arcfacesingle.charge.server.model.response.*;
import com.arcsoft.arcfacesingle.charge.server.util.FileUtils;
import com.arcsoft.arcfacesingle.charge.server.util.Md5Utils;
import com.arcsoft.arcfacesingle.charge.server.util.UnicodeUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.http.util.TextUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 模拟实现向设备端API发起http请求，使用原生RestTemplate发起网络请求
 *
 * @author
 * @date
 */
@SpringBootTest
class ServerApplicationTests {

    private String defaultSerial = "1234567890abcdefghijklmn";

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 配置服务器地址
     *
     * @param api
     * @return
     */
    private URI getUri(String api) {
        URI uri = null;
        try {
            uri = new URI(TestConstants.SERVER_ADDRESS + api);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return uri;
    }

    /**
     * 统一设置header中的“sign”（签名校验参数）
     *
     * @param json
     * @return
     */
    private HttpHeaders getHttpHeaders(String json) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("sign", getHeaderSign(json, getSignKey()));
        return httpHeaders;
    }

    /**
     * 将请求串和signKey加密后得到sign
     *
     * @param requestJson
     * @param signKey
     * @return
     */
    private String getHeaderSign(String requestJson, String signKey) {
        String strMd5 = requestJson + signKey;
        return Md5Utils.encode(strMd5);
    }

    /**
     * 模拟请求文档中的2.1接口（此接口无需在header中传入“sign”参数）
     */
    @Test
    public void getFingerprintInfo() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_GET_FINGER_PRINT_INFO);
        String json = "";
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        BaseResponse<DeviceFingerInfo> baseResponse = new Gson().fromJson(result, new TypeToken<BaseResponse<DeviceFingerInfo>>() {
        }.getType());
        if (baseResponse != null && baseResponse.getCode() == TestConstants.CODE_RESPONSE_SUCCESS) {
            DeviceFingerInfo info = baseResponse.getData();
            saveMacAddress(info.getMacAddress());
            saveSerialNumber(info.getSerialNumber());
        }
        System.out.print("getFingerprintInfo:" + result);
    }

    /**
     * 模拟请求接口文档中的2.2接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void connect() {
        Connect connect = new Connect();
        connect.setDeviceId(getDeviceId());
        connect.setIp("192.186.1.1");   //管理端ip地址，一般为本机或者服务器地址
        connect.setPort(8080);        //管理端端口，一般为本机或者服务器端口号
        connect.setMacAddress(getMacAddress());
        connect.setSerialNumber(getSerialNumber());
        connect.setSignType(2);
        connect.setSignKey(getSignKey());
        String json = new Gson().toJson(connect);
        URI uri = getUri(TestConstants.URI_EQUIPMENT_CONNECT);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("connect:" + result);
    }

    /**
     * 模拟请求接口文档中的2.3接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void getSetting() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_GET_SETTING);
        Connect connect = new Connect();
        connect.setSerialNumber(getSerialNumber());
        connect.setMacAddress(getMacAddress());
        String json = new Gson().toJson(connect);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        long time = System.currentTimeMillis();
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        long endTime = System.currentTimeMillis() - time;
        saveSetting(json);
        System.out.println("getSetting:" + result);
        System.out.println("time:" + endTime);
    }

    private void saveSetting(String json) {
        //todo 可以在此实现保存设备端参数逻辑
    }

    /**
     * 模拟请求接口文档中的2.4接口（此接口需要在header中传入“sign”参数）
     * <p>
     * 如果参数中有中文，生成“sign”时需要使用源数据，发送请求时需要将中文转成Unicode再执行exchange
     */
    @Test
    public void setting() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_SETTING);
        Setting setting = new Setting();
        String companyName = "这是公司名字";
        setting.setCompanyName(companyName);
        setting.setDeviceName("sample_deviceName");
        setting.setThreshold("0.8");
        setting.setInterval("1.5");
        setting.setVoiceMode("100");
        setting.setVoiceCustom("hello");
        setting.setLivenessType(1);
        String signJson = new Gson().toJson(setting);
        String nameUnicode = UnicodeUtils.string2Unicode(companyName);
        setting.setCompanyName(nameUnicode);
        String bodyJson = new Gson().toJson(setting).replace("\\\\", "\\");
        //加密成“sign”时需要原数据，发送请求时，需要将中文转成Unicode再执行exchange请求
        RequestEntity requestEntity = getRequestEntity(uri, signJson, bodyJson);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("setting:" + result);
    }

    /**
     * 模拟请求接口文档中的2.5接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void personList() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_PERSON_LIST);
        ReqPersonList list = new ReqPersonList();
        list.setPageIndex(0);
        list.setPageSize(2);
        list.setUpdateTime(15600000000L);
        String json = new Gson().toJson(list);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        savePerson(result);
        System.out.println("personList:" + result);
    }

    /**
     * 保存人员
     *
     * @param json
     */
    private void savePerson(String json) {
        RespBase<RespBasePage<Person>> personResp = new Gson().fromJson(json, new TypeToken<RespBase<RespBasePage<Person>>>() {
        }.getType());
        if (personResp.getCode() == TestConstants.CODE_RESPONSE_SUCCESS) {
            RespBasePage<Person> respBasePage = personResp.getData();
            if (respBasePage == null) {
                return;
            }
            List<Person> personList = respBasePage.getDataInfo();
            if (null != personList && personList.size() > 0) {
                List<PersonFace> faceList = personList.get(0).getFaceList();
                if (null != faceList && faceList.size() > 0) {
                    PersonFace face = faceList.get(0);
                    String imageBase64 = face.getImageBase64();
                    FileUtils.saveImageBase64(imageBase64, face.getImageName() + ".jpg");
                }
            }
        } else {
            //todo 实现失败逻辑
        }
    }

    /**
     * 模拟请求接口文档中的2.6接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void personAdd() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_ADD);
        long startTime = System.currentTimeMillis();
        int count = 0;
        int personCount = 1; //循环调用接口次数
        personAdd(count, personCount, uri);
        long endTime = System.currentTimeMillis() - startTime;
        System.out.println("总耗时：" + endTime + "ms");
    }

    /**
     * 模拟多次调用
     *
     * @param count
     * @param personCount
     * @param uri
     */
    private void personAdd(int count, int personCount, URI uri) {
        count++;
        PersonAdd personAdd = new PersonAdd();
//        personAdd.setPersonSerial(UUID.randomUUID().toString());
        personAdd.setPersonSerial(defaultSerial);
        String personName1 = "Tom";
        String personName2 = "中文名字、";
        personAdd.setTotal(1);
        personAdd.setPersonName(personName1 + personName2);
        personAdd.setPersonIdentifier("123ABC");
        personAdd.setIcCardNo("BM001ABC");
        personAdd.setPersonInfoType(3);
        String json = new Gson().toJson(personAdd);
        //如接口2.7备注说明，参数“faceList”不参与“sign”的生成
        RequestEntity.BodyBuilder bodyBuilder = RequestEntity
                .post(uri)
                .headers(getHttpHeaders(json))
                .contentType(MediaType.TEXT_PLAIN);
        List<PersonAddFace> faceList = new ArrayList<>();
        PersonAddFace face = new PersonAddFace();
        face.setImageName("sample_person");
        String imagePath = "d:\\sample_person.jpg";
        String base64 = FileUtils.image2Base64(imagePath);
        String md5 = Md5Utils.encode(base64);
        face.setImageBase64(base64);
        face.setImageMD5(md5);
        faceList.add(face);
        personAdd.setFaceList(faceList);
        //发送请求时，需要将中文转成Unicode再执行exchange请求
        String personName3 = personName1 + UnicodeUtils.string2Unicode(personName2);
        personAdd.setPersonName(personName3);
        String json2 = new Gson().toJson(personAdd).replace("\\\\", "\\");
        RequestEntity requestEntity = bodyBuilder.body(json2);
        long time = System.currentTimeMillis();
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        long end = System.currentTimeMillis() - time;
        System.out.println("调用接口耗时：" + end + "ms");
        String result = responseEntity.getBody();
        System.out.println(result);
        RespBase respBase = new Gson().fromJson(result, RespBase.class);
        if (respBase.getCode() == 200 && count < personCount) {
            personAdd(count, personCount, uri);
        }
    }

    /**
     * 模拟实现2.7接口功能逻辑：添加多个人员到管理端
     */
    @Test
    public void addPersonMultiple() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_ADD_MULTIPLE);
        int personSize = 10; //一次性添加的人员数
        int pageCount = 2;  //循环调用接口次数
        String imgPath = "d:\\sample_person.jpg";
        List<FileSystemResource> fileSystemResources = new ArrayList<>();
        for (int i = 0; i < personSize; i++) {
            FileSystemResource resource = new FileSystemResource(imgPath);
            fileSystemResources.add(resource);
        }
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        PersonAddList personAddList = new PersonAddList();
        List<PersonAdd> personAdds = new ArrayList<>();
        for (int i = 0; i < personSize; i++) {
            PersonAdd personAdd = new PersonAdd();
            personAdd.setPersonName("哈哈" + i);
            personAdd.setPersonSerial(UUID.randomUUID().toString());
            personAdd.setPersonIdentifier("FM00" + i);
            if (i % 2 == 0) {
                personAdd.setPersonInfoType(1);
            } else {
                personAdd.setPersonInfoType(3);
            }
            personAdd.setIcCardNo("AM000" + i);
            List<PersonAddFace> faces = new ArrayList<>();
            PersonAddFace addFace = new PersonAddFace();
            String imageName1 = "sample_person" + i + ".jpg";
            addFace.setImageName(imageName1);
            addFace.setFaceId(UUID.randomUUID().toString());
            faces.add(addFace);
            personAdd.setFaceList(faces);
            personAdds.add(personAdd);
        }
        personAddList.setPersonAddList(personAdds);
        personAddList.setRegisterComplete(false);
        personAddList.setThreadCount(3);
        String json = new Gson().toJson(personAddList);
        for (int i = 0; i < personSize; i++) {
            PersonAdd personAdd = personAddList.getPersonAddList().get(i);
            String faceId = personAdd.getFaceList().get(0).getFaceId();
            if (!TextUtils.isEmpty(faceId)) {
                form.add(faceId, fileSystemResources.get(i));
            }
        }
        form.add("content", json);
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("sign", getHeaderSign(json, getSignKey()));
        RequestEntity requestEntity = RequestEntity
                .post(uri)
                .headers(httpHeaders)
                .contentType(MediaType.MULTIPART_FORM_DATA)
                .body(form);
        long startTime = System.currentTimeMillis();
        int count = 0;
        exchange(requestEntity, count, pageCount);
        long endTime = System.currentTimeMillis() - startTime;
        System.out.println("总耗时：" + endTime + "ms");
    }

    /**
     * 模拟多次调用
     *
     * @param requestEntity
     * @param count
     * @param pageCount
     */
    private void exchange(RequestEntity requestEntity, int count, int pageCount) {
        count++;
        long time = System.currentTimeMillis();
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        long endTime = System.currentTimeMillis() - time;
        System.out.println("接口请求耗时：" + endTime);
        System.out.println(result);
        RespBase respBase = new Gson().fromJson(result, RespBase.class);
        if (respBase.getCode() == 200 && count < pageCount) {
            exchange(requestEntity, count, pageCount);
        }
    }

    /**
     * 模拟请求接口文档中的2.8接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void personDelete() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_DELETE);
        PersonAdd person = new PersonAdd();
        person.setTotal(1);
        person.setPersonSerial(defaultSerial);
        String json = new Gson().toJson(person);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("personDelete:" + result);
    }

    /**
     * 模拟请求接口文档中的2.9接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void doorAuthority() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_DOOR_AUTHORITY);
        DoorAuthority authority = new DoorAuthority();
        authority.setPersonSerial(defaultSerial);
        authority.setMorningStartTime("01:00:00");
        authority.setMorningEndTime("01:00:10");
        authority.setNoonStartTime("00:00:00");
        authority.setNoonEndTime("00:00:00");
        authority.setNightStartTime("00:00:00");
        authority.setNightEndTime("00:00:00");
        String json = new Gson().toJson(authority);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("doorAuthority:" + result);
    }

    /**
     * 模拟请求接口文档中的2.10接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void doorAuthorityV2() {
        URI uri = getUri(TestConstants.URI_PERSON_MANAGE_DOOR_AUTHORITY_V2);
        DoorAuthorityV2 authority = new DoorAuthorityV2();
        authority.setPersonSerial(defaultSerial);
        List<DoorAuthorityV2.DoorAuthorityDetail> authorityDetails = new ArrayList<>();
        DoorAuthorityV2.DoorAuthorityDetail authorityDetail = new DoorAuthorityV2.DoorAuthorityDetail();
        authorityDetail.setStartDate("2020-03-11");
        authorityDetail.setEndDate("2020-03-13");
        authorityDetail.setWorkingDays("1,2,3,4,5");
        List<DoorAuthorityV2.DoorAuthorityDetail.TimeAuthority> timeAuthorityList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            DoorAuthorityV2.DoorAuthorityDetail.TimeAuthority timeAuthority = new DoorAuthorityV2.DoorAuthorityDetail.TimeAuthority();
            timeAuthority.setStartTime(("0" + i) + ":" + "00" + ":" + "00");
            timeAuthority.setEndTime(("0" + i) + ":" + "50" + ":" + "00");
            timeAuthorityList.add(timeAuthority);
        }
        authorityDetail.setTimeRangeList(timeAuthorityList);
        authorityDetails.add(authorityDetail);
        authority.setAuthorityDetails(authorityDetails);
        String json = new Gson().toJson(authority);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("doorAuthorityV2:" + result);
    }

    /**
     * 模拟请求接口文档中的2.11接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void getLogo() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_GET_LOGO);
        GetLogo getLogo = new GetLogo();
        getLogo.setType(GetLogo.TYPE_MAIN);
        String json = new Gson().toJson(getLogo);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        saveLogo(result);
        System.out.println("getLogo:" + result);
    }

    /**
     * 保存设备端logo
     *
     * @param json
     */
    private void saveLogo(String json) {
        BaseResponse<Logo> baseLogo = new Gson().fromJson(json, new TypeToken<BaseResponse<Logo>>() {
        }.getType());
        if (baseLogo.getCode() == TestConstants.CODE_RESPONSE_SUCCESS) {
            Logo logo = baseLogo.getData();
            if (logo != null) {
                String mainBase64 = logo.getMainLogo();
                if (!TextUtils.isEmpty(mainBase64)) {
                    //TODO 实现保存设备端logo逻辑
                    FileUtils.saveImageBase64Png(mainBase64, "mainLogo.png");
                }
            }
        } else {
            //todo 实现失败逻辑
        }
    }

    /**
     * 模拟请求接口文档中的2.12接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void setLogo() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_SET_LOGO);
        SetLogo setLogo = new SetLogo();
        setLogo.setOperation(1);
        setLogo.setMainLogoId("111");
        String json = new Gson().toJson(setLogo);
        //如2.10接口文档备注中说明，参数“mainLogoBase64”不参与“sign”的生成
        RequestEntity.BodyBuilder bodyBuilder = RequestEntity
                .post(uri)
                .headers(getHttpHeaders(json))
                .contentType(MediaType.TEXT_PLAIN);
        String imagePath = "d:\\mainLogo.jpg";
        String base64 = FileUtils.image2Base64(imagePath);
        setLogo.setMainLogoBase64(base64);
        String json2 = new Gson().toJson(setLogo);
        RequestEntity entity = bodyBuilder.body(json2);
        ResponseEntity<String> responseEntity = restTemplate.exchange(entity, String.class);
        String result = responseEntity.getBody();
        System.out.println("setLogo:" + result);
    }

    /**
     * 模拟请求接口文档中的2.13接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void cleanData() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_CLEAN_DATA);
        String json = "{}";
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.print("cleanData:" + result);
    }

    /**
     * 模拟请求接口文档中的2.14接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void reboot() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_REBOOT);
        String json = "{}";
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> response = restTemplate.exchange(requestEntity, String.class);
        String result = response.getBody();
        System.out.println("reboot:" + result);
    }

    /**
     * 模拟请求接口文档中的2.15接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void openDoor() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_OPEN_DOOR);
        String json = "{}";
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> response = restTemplate.exchange(requestEntity, String.class);
        String result = response.getBody();
        System.out.println("openDoor:" + result);
    }

    /**
     * 模拟请求接口文档中的2.16接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void packageAuthority() {
        URI uri = getUri(TestConstants.URI_PACKAGE_AUTHORITY);
        PackageAuthority authority = new PackageAuthority();
        authority.setVersionCode(70);
        authority.setPackageName("com.arcsoft.arcfacesingle.charge");
        authority.setVersionName("3.0.1");
        String json = new Gson().toJson(authority);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("packageAuthority:" + result);
    }

    /**
     * 模拟请求接口文档中的2.17接口，此接口涉及到file文件的传输，content-type类型为multipart/form-data
     * 调用2.15接口之前，要先调用2.14接口验证版本信息
     */
    @Test
    public void packageTransfer() {
        URI uri = getUri(TestConstants.URI_PACKAGE_TRANSFER);
        String apkPath = "d:\\1.apk";
        FileSystemResource fileSystemResource = new FileSystemResource(apkPath);
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        form.add("file", fileSystemResource);
        RequestEntity requestEntity = RequestEntity
                .post(uri)
                .contentType(MediaType.MULTIPART_FORM_DATA)
                .body(form);
        System.out.println("APK发送时间：" + System.currentTimeMillis());
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("packageTransfer:" + result);
    }

    /**
     * 模拟请求接口文档中的2.18接口（此接口需要在header中传入“sign”参数）
     */
    @Test
    public void disconnect() {
        URI uri = getUri(TestConstants.URI_EQUIPMENT_DISCONNECT);
        Disconnect disconnect = new Disconnect();
        String msgMd5 = Md5Utils.encode(getDeviceId() + "|" + getSignKey());
        disconnect.setVerification(msgMd5);
        String json = new Gson().toJson(disconnect);
        RequestEntity requestEntity = getRequestEntity(uri, json);
        ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
        String result = responseEntity.getBody();
        System.out.println("disconnect:" + result);
    }

    private RequestEntity getRequestEntity(URI uri, String json) {
        return getRequestEntity(uri, json, json);
    }

    private RequestEntity getRequestEntity(URI uri, String signJson, String bodyJson) {
        return RequestEntity
                .post(uri)
                .headers(getHttpHeaders(signJson))
                .contentType(MediaType.TEXT_PLAIN)
                .body(bodyJson);
    }

    /**
     * 模拟生成signKey
     *
     * @return
     */
    private String getSignKey() {
        return "0123456789abcdefghijk";
    }

    /**
     * 模拟生成deviceId
     */
    private int getDeviceId() {
        return 1;
    }

    /**
     * 获取macAddress
     *
     * @return
     */
    private String getMacAddress() {
        return "123456789";
    }

    /**
     * 保存macAddress
     *
     * @param macAddress
     */
    public void saveMacAddress(String macAddress) {
    }

    /**
     * 获取SN号
     *
     * @return
     */
    public String getSerialNumber() {
        return "abcdefg";
    }

    /**
     * 保存macAddress
     *
     * @param serialNumber
     */
    public void saveSerialNumber(String serialNumber) {
    }
}
